### Alizade, Dancygier, Ditlmann
### "National Penalties Reversed"
### Replication Code 
### Table A2
### For questions, contact jalizade@princeton.edu

# setup
rm(list = ls())
setwd("C:/Users/Jey/Dropbox/WZB/NaturalizationExperiment/Submission/JOP/replication_JOP/data")
library(foreign)
dat <- read.dta("data_experimental.dta")
datmun <- read.dta("data_covars_mun.dta")

# filter first experiment
dat <- dat[dat$e2_treated==1,]
datmun <- datmun[datmun$e2_treated==1,]

# function to calculate and display summary statistics
sumstats <- function(df, var) {
  data.frame(
    N=sum(!is.na(df[,var])), 
    Mean=mean(df[,var], na.rm=T), 
    SD=sd(df[,var], na.rm=T), 
    Min=min(df[,var], na.rm=T), 
    Max=max(df[,var], na.rm=T)
  ) 
}

# get summary statistics for individual-level variables
t(sapply(c("e2_response", "e2_fempol", "e2_leftpol", "e2_cfpol"), function(x) sumstats(dat, x)))

# get summary statistics for aggregate-level variables
t(sapply(c("pct_turk_pop", "pct_forcit_pop", "pop", "pop_density", "pct_welfare", "pct_coll_qual", "e2_n_council", "e2_pct_left", "e2_pct_bigpart"), 
         function(x) sumstats(datmun, x)))
